<?php

class EmailBlastController extends Controller
{
	public function actionIndex()
	{
		$model = new EmailBlastForm;
		$contacts=Guestbook::model()->findAll('`update` = 1');
		if(isset($_POST['EmailBlastForm']))
		{
			$model->attributes=$_POST['EmailBlastForm'];
			if($model->validate())
			{
				$this->sendEmail(
				$_POST['EmailBlastForm']['to'], 
				$_POST['EmailBlastForm']['subject'], 
				$_POST['EmailBlastForm']['message']);
				$this->redirect(array('success'));
				//$this->refresh();
			}
		}
		$this->render('index', array('contacts'=>$contacts,'model'=>$model));
	}
	public function actionSuccess()
	{
		$this->render('success');
	}
	public function actionSendEmail()
	{
		$email = Yii::app()->email;
		$email->to = 'taptip1@localhost,taptip2@localhost';
		$email->subject = 'Hello';
		$email->message = 'Hello brother';
		$email->send();
	}
	
	public function sendEmail($to, $subj, $message)
	{
		$email = Yii::app()->email;
		$email->to = $to;
		$email->subject = $subj;
		$email->message = $message;
		$email->send();
	}
		
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}